#pragma once
#include <stdio.h>
#include <string>

enum
{
    DIVZERO = 1,
    UNKNOW
};
std::string g_op = "+-*/";
struct task
{
public:
    task()
    {}
    task(int a, int b, char op)
    :_a(a), _b(b), _op(op), _result(0), _exitcode(0)
    {}

    void run()
    {
        switch(_op)
        {
            case '+':
                _result = _a + _b;
                break;
            case '-':
                _result = _a - _b;
                break;
            case '*':
                _result = _a * _b;
                break;
            case '/':
                if (_b == 0)
                {
                    _exitcode = DIVZERO;
                }
                else
                {
                     _result = _a / _b;
                }      
                break;
            default:
                _exitcode = UNKNOW;
                break;
            }
        //printf("%d+%d结果:%d\n", _a, _b, _a + _b);
    }

    std::string getresult()
    {
        std::string str = std::to_string(_a) + _op  + std::to_string(_b);
        str += "=";
        str += std::to_string(_result);
        str += " [exit:";
        str += std::to_string(_exitcode);
        str += "]";

        return str;
    }

    std::string gettask()
    {
        std::string str = std::to_string(_a) + _op  + std::to_string(_b);
        return str;
    }

private:
    int _a;
    int _b;
    char _op;

    int _result;
    int _exitcode;
};